//
//  RegisterViewController.m
//  ChatForHot
//
//  Created by FLY on 2018/10/10.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "RegisterViewController.h"
#import "RegisterInfoViewController.h"
#import "PolicyMessageViewController.h"
#import "HOTCHATPopVIew.h"
@interface RegisterViewController ()<HOTCHATPopDelegate>

@property (nonatomic, assign) NSInteger HOTCHATsex;
@property (nonatomic, strong) HOTCHATPopVIew *popView;
@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.isHiddenNav = YES;
}
- (void)HOTCHATInsertSubViews{
    
    [self.view addSubview:self.HOTCHATbackImgView];
    [self.view addSubview:self.HOTCHATbackBtn];
    [self.view addSubview:self.HOTCHATtitleLab];
    [self.view addSubview:self.HOTCHATlineView];
    [self.view addSubview:self.HOTCHATwommenBtn];
    [self.view addSubview:self.HOTCHATwommenLab];
    [self.view addSubview:self.HOTCHATmanBtn];
    [self.view addSubview:self.HOTCHATmanLab];
    [self.view addSubview:self.HOTCHATacceptBtn];
    [self.view addSubview:self.HOTCHATacceptLab];
    
    [self.HOTCHATbackImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
    }];
    [self.HOTCHATbackBtn mas_updateConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view).mas_offset(34);
        make.left.equalTo(self.view.mas_left).mas_offset(15);
    }];
    [self.HOTCHATtitleLab mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).mas_offset(96);
        make.centerX.equalTo(self.view);
    }];
    [self.HOTCHATwommenBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.HOTCHATtitleLab.mas_bottom).mas_offset(54);
        make.centerX.equalTo(self.view);
    }];
    [self.HOTCHATwommenLab mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.HOTCHATwommenBtn.mas_bottom).mas_offset(7);
        make.centerX.equalTo(self.HOTCHATwommenBtn.mas_centerX);
    }];
    [self.HOTCHATlineView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.HOTCHATwommenLab.mas_bottom).mas_offset(35);
        make.left.equalTo(self.view.mas_left).mas_offset(70);
        make.right.equalTo(self.view.mas_right).mas_offset(-70);
        make.height.mas_equalTo(0.5);
    }];
    [self.HOTCHATmanBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.HOTCHATlineView.mas_bottom).mas_offset(40);
        make.centerX.equalTo(self.view);
    }];
    [self.HOTCHATmanLab mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.HOTCHATmanBtn.mas_bottom).mas_offset(7);
        make.centerX.equalTo(self.HOTCHATmanBtn.mas_centerX);
    }];
    [self.HOTCHATacceptBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.height.width.equalTo(self.HOTCHATacceptLab.mas_height);
        make.right.equalTo(self.HOTCHATacceptLab.mas_left).mas_offset(-3);
        make.centerY.equalTo(self.HOTCHATacceptLab.mas_centerY);
    }];
    [self.HOTCHATacceptLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(14);
        make.bottom.equalTo(self.view.mas_bottom).mas_offset(-18);
        make.centerX.equalTo(self.view);
    }];
    
    
}
//lazzy
- (UIImageView *)HOTCHATbackImgView{
    
    if (_HOTCHATbackImgView == nil) {
        
        _HOTCHATbackImgView = [[UIImageView alloc]init];
        _HOTCHATbackImgView.image = [UIImage imageNamed:@"l_bg"];
        _HOTCHATbackImgView.userInteractionEnabled = YES;
    }
    return _HOTCHATbackImgView;
}
- (UIButton *)HOTCHATbackBtn{
    
    if (_HOTCHATbackBtn == nil) {
        
        _HOTCHATbackBtn = [[UIButton alloc]init];
        [_HOTCHATbackBtn setBackgroundImage:[UIImage imageNamed:@"l_back"] forState:UIControlStateNormal];
        [_HOTCHATbackBtn setBackgroundImage:[UIImage imageNamed:@"l_back_hig"] forState:UIControlStateHighlighted];
        [_HOTCHATbackBtn addTarget:self action:@selector(HOTCHATbackAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _HOTCHATbackBtn;
}
- (UILabel *)HOTCHATtitleLab{
    
    if (_HOTCHATtitleLab == nil) {
        
        _HOTCHATtitleLab = [[UILabel alloc]init];
        _HOTCHATtitleLab.textColor = [UIColor whiteColor];
        _HOTCHATtitleLab.textAlignment = NSTextAlignmentCenter;
        _HOTCHATtitleLab.font = [UIFont systemFontOfSize:30];
        _HOTCHATtitleLab.text = NSLocalizedString(@"StrN06", nil);
        
    }
    return _HOTCHATtitleLab;
}
- (UIButton *)HOTCHATwommenBtn{
    
    if (_HOTCHATwommenBtn == nil) {
        
        _HOTCHATwommenBtn = [[UIButton alloc]init];
        _HOTCHATwommenBtn.tag = 0;
        [_HOTCHATwommenBtn setBackgroundImage:[UIImage imageNamed:@"l_signup_gender_female"] forState:UIControlStateNormal];
        [_HOTCHATwommenBtn setBackgroundImage:[UIImage imageNamed:@"l_signup_gender_female_hig"] forState:UIControlStateSelected];
        [_HOTCHATwommenBtn addTarget:self action:@selector(HOTCHATregisterAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _HOTCHATwommenBtn;
}
- (UILabel *)HOTCHATwommenLab{
    
    if (_HOTCHATwommenLab == nil) {
        
        _HOTCHATwommenLab = [[UILabel alloc]init];
        _HOTCHATwommenLab.textColor = [UIColor whiteColor];
        _HOTCHATwommenLab.textAlignment = NSTextAlignmentCenter;
        _HOTCHATwommenLab.font = [UIFont systemFontOfSize:16];
        _HOTCHATwommenLab.text = NSLocalizedString(@"StrN07", nil);
    }
    return _HOTCHATwommenLab;
}
- (UIButton *)HOTCHATmanBtn{
    
    if (_HOTCHATmanBtn == nil) {
        
        _HOTCHATmanBtn = [[UIButton alloc]init];
        _HOTCHATmanBtn.tag = 1;
        [_HOTCHATmanBtn setBackgroundImage:[UIImage imageNamed:@"l_signup_gender_male"] forState:UIControlStateNormal];
        [_HOTCHATmanBtn setBackgroundImage:[UIImage imageNamed:@"l_signup_gender_male_hig"] forState:UIControlStateSelected];
        [_HOTCHATmanBtn addTarget:self action:@selector(HOTCHATregisterAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _HOTCHATmanBtn;
}
- (UILabel *)HOTCHATmanLab{
    
    if (_HOTCHATmanLab == nil) {
        
        _HOTCHATmanLab = [[UILabel alloc]init];
        _HOTCHATmanLab.textColor = [UIColor whiteColor];
        _HOTCHATmanLab.textAlignment = NSTextAlignmentCenter;
        _HOTCHATmanLab.font = [UIFont systemFontOfSize:16];
        _HOTCHATmanLab.text = NSLocalizedString(@"StrN07", nil);
    }
    return _HOTCHATmanLab;
}
- (UIButton *)HOTCHATacceptBtn{
    
    if (_HOTCHATacceptBtn == nil) {
        
        _HOTCHATacceptBtn = [[UIButton alloc] init];
        _HOTCHATacceptBtn.selected = YES;
        
        [_HOTCHATacceptBtn setImage:[UIImage imageNamed:@"l_terms_off"] forState:(UIControlStateNormal)];
        [_HOTCHATacceptBtn setImage:[UIImage imageNamed:@"l_terms_on"] forState:(UIControlStateSelected)];
        [_HOTCHATacceptBtn  addTarget:self action:@selector(HOTCHATAcceptAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _HOTCHATacceptBtn;
}
- (UILabel *)HOTCHATacceptLab{
    
    if (_HOTCHATacceptLab == nil) {
        
        _HOTCHATacceptLab = [[UILabel alloc]init];
        _HOTCHATacceptLab.userInteractionEnabled = YES;
        _HOTCHATacceptLab.textColor = [UIColor whiteColor];
        _HOTCHATacceptLab.textAlignment = NSTextAlignmentLeft;
        _HOTCHATacceptLab.font = [UIFont systemFontOfSize:10];
        _HOTCHATacceptLab.text = NSLocalizedString(@"StrN09", nil);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(HOTCHATlookPolicytext)];
        [_HOTCHATacceptLab addGestureRecognizer:tap];
    }
    return _HOTCHATacceptLab;
}
- (UIView *)HOTCHATlineView{
    
    if (_HOTCHATlineView == nil) {
        
        _HOTCHATlineView = [[UIView alloc]init];
        _HOTCHATlineView.backgroundColor = [UIColor whiteColor];
    }
    return _HOTCHATlineView;
}
- (void)HOTCHATAcceptAction{
    
    self.HOTCHATacceptBtn.selected = !self.HOTCHATacceptBtn.selected;
}
- (void)HOTCHATlookPolicytext{
    
    PolicyMessageViewController *VC = [[PolicyMessageViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}
//backaction
- (void)HOTCHATbackAction{
    
    [self.navigationController popViewControllerAnimated:YES];
}
//registerAction
- (void)HOTCHATregisterAction:(UIButton *)btn{
    
    if (!self.HOTCHATacceptBtn.selected) {
        
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:NSLocalizedString(@"StrN10", nil) delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alert show];
    }
    
    self.popView = [[HOTCHATPopVIew alloc] init];
    self.popView.delegate = self;
    self.popView.frame = self.view.bounds;
    [self.popView show];
    self.HOTCHATsex = btn.tag;
}

- (void)HOTCHATagreeButtonDidTouch {
    RegisterInfoViewController *VC = [[RegisterInfoViewController alloc]init];
    VC.sex = self.HOTCHATsex;
    [self.navigationController pushViewController:VC animated:YES];
    [self.popView hideView];
}
@end
